<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        //Promise基本使用
        console.log(typeof Promise) //function

        var p = new Promise((resolve, reject) => {
            setTimeout(() => {
                var flag = false;
                if (flag) {
                    //正常情况
                    resolve('hello');
                } else {
                    //异常情况
                    reject('error')
                }
            }, 100);
        });

        p.then((data) => {
            console.log(data);
        }, (err) => {
            console.log(err);
        })
    </script>
</body>

</html>